<template>
	<view class="calendar-content">
		<uni-forms ref="form" :model="form">
			<uni-card>
				<uni-row>
					<uni-col :span="5" class="title">设备编号:</uni-col>
					<uni-col :span="5" class="content">{{form.instrumentId}}</uni-col>
					<uni-col :span="3" class="title">规格:</uni-col>
					<uni-col :span="4" class="content">{{form.specification}}</uni-col>
				</uni-row>
				<uni-row>
					<uni-col :span="5" class="title">设备型号:</uni-col>
					<uni-col :span="18" class="content">{{form.modelNumber}}</uni-col>
				</uni-row>


				<uni-row>
					<uni-col :span="5" class="title1">存放地:</uni-col>
					<uni-col :span="18" class="content1">{{form.storageLocation}}</uni-col>
				</uni-row>

				<uni-row>
					<uni-col :span="5" class="title">设备名称:</uni-col>
					<uni-col :span="18" class="content">{{form.instrumentName}}</uni-col>
				</uni-row>

				<uni-row>
					<uni-col :span="5" class="title1">领用人:</uni-col>
					<uni-col :span="4" class="content1">{{form.receiverName}}</uni-col>
					<uni-col :span="5" class="title1">设备类型:</uni-col>
					<uni-col :span="8" class="content1">{{type(form.equipmentType)}}</uni-col>
				</uni-row>
			</uni-card>
		</uni-forms>

		<view>
			<uni-calendar class="aaa" @change="change($event, 'showRight')" :startDate="range.StartTime"
				:endDate="range.EndTime" :selected="info.selected" />
		</view>

		<view class="example-info"><text>预约时间为早上8：00到晚上17：00</text></view>

		<view class="example-body">
			<uni-drawer ref="showRight" mode="right" :width="300" :mask-click="false">
				<view class="scroll-view">

					<scroll-view class="scroll-view-box" scroll-y="true">
						<view class="title-split">
							<text>当日预约信息</text>
						</view>

						<view v-if="tableriqi==''">
							<uni-card>
								<view class="card-text">
									<text class="card-text"> </text><br>
									<text class="card-text">没有预约信息</text><br>
									<text class="card-text"> </text><br>
								</view>
							</uni-card>
						</view>
						<view v-for="(item, index) in tableriqi" :key="index">

							<uni-card>
								<view>
									<text>预约用户：{{item.name}}</text><br>
									<text>开始时间：{{item.appointmentStart}}</text><br>
									<text>结束时间：{{item.appointmentEnd}}</text>
								</view>
							</uni-card>

						</view>

						<view class="close">
							<button class="mini" @click="submit"><text class="word-btn-white">点击预约</text></button>
						</view>

						<view class="close">
							<button class="mini" @click="closeDrawer('showRight')"><text
									class="word-btn-white">返回</text></button>
						</view>

					</scroll-view>
				</view>
			</uni-drawer>
		</view>


	</view>
</template>
<script>
	import {
		getEquipment
	} from "@/api/module/lyq/equip.js"
	import {
		listAppointment,
		getAppointment
	} from "@/api/module/lyq/appoint.js"
	import config from "../../../config"
	import {
	  getConfigKey
	 } from "@/api/system/config.js"
	/**
	 * 获取任意时间
	 */
	function getDate(date, AddDayCount = 0) {
		if (!date) {
			date = new Date()
		}
		if (typeof date !== 'object') {
			date = date.replace(/-/g, '/')
		}
		const dd = new Date(date)

		dd.setDate(dd.getDate() + AddDayCount) // 获取AddDayCount天后的日期

		const y = dd.getFullYear()
		const m = dd.getMonth() + 1 < 10 ? '0' + (dd.getMonth() + 1) : dd.getMonth() + 1 // 获取当前月份的日期，不足10补0
		const d = dd.getDate() < 10 ? '0' + dd.getDate() : dd.getDate() // 获取当前几号，不足10补0
		return {
			fullDate: y + '-' + m + '-' + d,
			year: y,
			month: m,
			date: d,
			day: dd.getDay()
		}
	}
	export default {
		components: {},
		data() {
			return {
				showCalendar: false,
				info: {
					lunar: true,
					range: true,
					insert: false,
					selected: []
				},
				table: {},
				range: {
					StartTime: this.getNowTime(),
					EndTime: this.getBeforeDate(-6)
				},
				tableriqi: {},
				tableriqi1: {},
				// 遮罩层
				loading: true,
				// 选中数组
				ids: [],
				arr: [],
				// 非单个禁用
				single: true,
				// 非多个禁用
				multiple: true,
				// 显示搜索条件
				showSearch: true,
				// 总条数
				total: 0,
				he:{
					heji: 0,
					heji1: 0,
					heji2: 0,
					heji3: 0,
					heji4: 0,
					heji5: 0,
					heji6: 0
				},
				// 预约信息表格数据
				appointmentList: [],
				// 弹出层标题
				title: "",
				shebeiid: "",
				riqi: {
					pageNum: 1,
					pageSize: 10,
					studentId: null,
					department: null,
					name: null,
					gender: null,
					phone: null,
					idCard: null,
					teacherName: null,
					teacherId: null,
					equipmentType: null,
					applicationDepartment: null,
					instrumentId: null,
					instrumentName: null,
					modelNumber: null,
					specification: null,
					unitPrice: null,
					classifyNumber: null,
					purchaseDate: null,
					receiverId: null,
					receiverName: null,
					manufacturers: null,
					storageDate: null,
					storageLocation: null,
					expenditureSubject: null,
					useDirection: null,
					firstUse: null,
					appointmentStart: null,
					appointmentEnd: null,
					sbumitTime: null,
					auditStatus: null,
					teacherResult: null,
					adminResult: null,
					teacherTime: null,
					adminTime: null,
					userId: null,
					deptId: null,
					createBy: null,
					createTime: null,
					updateBy: null,
					updateTime: null,
					remark: null,
					note1: null,
					note2: null,
					note3: null,
					note4: null,
					note5: null,
					note6: null,
					note7: null,
					note8: null,
					note9: null,
					note10: null
				},
				// 查询参数
				queryParams: {
					pageNum: 1,
					pageSize: 10,
					studentId: null,
					department: null,
					name: null,
					gender: null,
					phone: null,
					idCard: null,
					teacherName: null,
					teacherId: null,
					equipmentType: null,
					applicationDepartment: null,
					instrumentId: null,
					instrumentName: null,
					modelNumber: null,
					specification: null,
					unitPrice: null,
					classifyNumber: null,
					purchaseDate: null,
					receiverId: null,
					receiverName: null,
					manufacturers: null,
					storageDate: null,
					storageLocation: null,
					expenditureSubject: null,
					useDirection: null,
					firstUse: null,
					appointmentStart: null,
					appointmentEnd: null,
					sbumitTime: null,
					auditStatus: null,
					teacherResult: null,
					adminResult: null,
					teacherTime: null,
					adminTime: null,
					userId: null,
					deptId: null,
					createBy: null,
					createTime: null,
					updateBy: null,
					updateTime: null,
					remark: null,
					note1: null,
					note2: null,
					note3: null,
					note4: null,
					note5: null,
					note6: null,
					note7: null,
					note8: null,
					note9: null,
					note10: null
				},

				equipType: {},
				equipOptions: [],
				// 表单参数
				form: {
					appointmentStart: null,
					appointmentEnd: null
				},
				// 表单校验
				rules: {}
			}
		},


		created() {
			this.getConfig();
			this.shebeiid = this.$route.query.id;
			this.getDicts("yh_equip_type").then(response => {
				this.equipOptions = response.data;
				for (var i = 0; i < this.equipOptions.length; i++) {
					this.equipType[this.equipOptions[i].dictValue] = this.equipOptions[i].dictLabel
				}
				this.getList()
			});
			if (this.shebeiid) {
				// 获取表详细信息
				getEquipment(this.shebeiid).then(res => {
					this.form = res.data;
				});

			}
			this.getList()
			this.panduan()
			
		},
		methods: {

			// 显示转换
			type: function(equipType) {

				return this.equipType[equipType]
			},
			open() {
				this.$refs.calendar.open()
			},
			change(e, d) {
				if (this.shebeiid) {
					// 获取表详细信息
					getEquipment(this.shebeiid).then(res => {
						this.riqi.instrumentId = res.data.instrumentId;
						this.riqi.note2 = e.fulldate;
						this.riqi.note1 = 0;
						// console.log(e)
						// console.log("赋予1：" + this.riqi.instrumentId);
						// console.log("赋予2：" + this.riqi.note2);
						this.getListriqi()
						this.$refs[d].open();
						// if(e.fulldate==getDate(new Date()).fullDate&&this.he.heji>=13)
						// {this.$modal.msgError("当天时间段预约已满");}
						// else if(e.fulldate==getDate(new Date(),+1).fullDate&&this.he.heji1>=13)
						// {this.$modal.msgError("当天时间段预约已满");}
						// else if(e.fulldate==getDate(new Date(),+2).fullDate&&this.he.heji2>=13)
						// {this.$modal.msgError("当天时间段预约已满");}
						// else if(e.fulldate==getDate(new Date(),+3).fullDate&&this.he.heji3>=13)
						// {this.$modal.msgError("当天时间段预约已满");}
						// else if(e.fulldate==getDate(new Date(),+4).fullDate&&this.he.heji4>=13)
						// {this.$modal.msgError("当天时间段预约已满");}
						// else if(e.fulldate==getDate(new Date(),+5).fullDate&&this.he.heji5>=13)
						// {this.$modal.msgError("当天时间段预约已满");}
						// else if(e.fulldate==getDate(new Date(),+6).fullDate&&this.he.heji6>=13)
						// {this.$modal.msgError("当天时间段预约已满");}
						// else{this.$refs[d].open();}
						
					});
				}

			},

			
			getConfig(){
			    getConfigKey("sys.time.judgment").then(response => {
				
			          this.fanwei = response.msg;
					  this.arr =this.fanwei.split(',');
					  // console.log(this.arr)
					  // console.log(this.arr[0])					  
					  // console.log(this.arr[1])
					  // console.log(this.arr[2])
					  // console.log(this.arr[3])
			        });
				getConfigKey("sys.time.total").then(response => {
				      this.xian = response.msg;
					  // console.log(this.xian)
				    });
			   },
//yituodabian
			panduan() {
				getEquipment(this.shebeiid).then(res => {
					this.riqi.instrumentId = res.data.instrumentId;
					this.riqi.note2 = getDate(new Date(), 0).fullDate;
					// console.log("今日" + getDate(new Date(),+1).fullDate);
					this.riqi.note1 = 0;
					listAppointment(this.riqi).then(res => {
						this.tableriqi1 = res.rows;
						this.total = res.total;
						var heji = 0
						for (var i = 0; i < this.tableriqi1.length; i++) {
							let startHour = new Date(this.tableriqi1[i].appointmentStart).getHours();
							       let endHour = new Date(this.tableriqi1[i].appointmentEnd).getHours();
							       if (startHour < this.arr[0]) {
							           if (endHour <= this.arr[0]) {
							               heji += 0;
							           } else if (endHour <= this.arr[1]) {
							               heji += endHour - this.arr[0];
							           } else if (endHour <= this.arr[2]) {
							               heji += this.arr[1] - this.arr[0];
							           }else if (endHour <= this.arr[3]) {
							               heji += endHour - this.arr[0]- -this.arr[1]-this.arr[2];
							           } else {
							               heji += endHour - this.arr[0]- -this.arr[1]-this.arr[2];
							           }
							       } else if (startHour < this.arr[1]) {
							           if (endHour <= this.arr[1]) {
							               heji += endHour - startHour;
							           } else if (endHour <= this.arr[2]) {
							               heji += this.arr[1] - startHour;
							           } else if (endHour <= this.arr[3]) {
							               heji += endHour - startHour - 2;
							           } else {
							               heji += endHour - startHour - 2;
							           }
							       } else if (startHour < this.arr[2]) {
							           if (endHour <= this.arr[2]) {
							               heji += 0;
							           } else if (endHour <= this.arr[3]) {
							               heji = heji + endHour - this.arr[2];
							           } else {
							               heji = heji + endHour - this.arr[2];
							           }
							       } else if (startHour < this.arr[3]) {
							           if (endHour <= this.arr[3]) {
							               heji += endHour - startHour;
							           } else {
							               heji += this.arr[3] - startHour - -1;
							           }
							       } else {
							           heji += 1;
							       }
									console.log("合计"+heji)
						}
						this.he.heji=heji;
						console.log("a"+this.he.heji)
						if (heji >= this.xian) {
							const newItem = {
								date: getDate(new Date()).fullDate,
								info: '预约已满'
							}
							this.info.selected.push(newItem);
						}
					});
				});
				getEquipment(this.shebeiid).then(res => {
					this.riqi.instrumentId = res.data.instrumentId;
					this.riqi.note2 = getDate(new Date(), +1).fullDate;
					// console.log("今日" + getDate(new Date(),+1).fullDate);
					this.riqi.note1 = 0;
					listAppointment(this.riqi).then(res => {
						this.tableriqi1 = res.rows;
						this.total = res.total;
						var heji1 = 0
						for (var i = 0; i < this.tableriqi1.length; i++) {
							let startHour = new Date(this.tableriqi1[i].appointmentStart).getHours();
							       let endHour = new Date(this.tableriqi1[i].appointmentEnd).getHours();
							       if (startHour < this.arr[0]) {
							           if (endHour <= this.arr[0]) {
							               heji1 += 0;
							           } else if (endHour <= this.arr[1]) {
							               heji1 += endHour - this.arr[0];
							           } else if (endHour <= this.arr[2]) {
							               heji1 += this.arr[1] - this.arr[0];
							           } else if (endHour <= this.arr[3]) {
							               heji1 += endHour - this.arr[0]- -this.arr[1]-this.arr[2];
							           } else {
							               heji1 += endHour - this.arr[0]- -this.arr[1]-this.arr[2];
							           }
							       } else if (startHour < this.arr[1]) {
							           if (endHour <= this.arr[1]) {
							               heji1 += endHour - startHour;
							           } else if (endHour <= this.arr[2]) {
							               heji1 += this.arr[1] - startHour;
							           } else if (endHour <= this.arr[3]) {
							               heji1 += endHour - startHour - 2;
							           } else {
							               heji1 += endHour - startHour - 2;
							           }
							       } else if (startHour < this.arr[2]) {
							           if (endHour <= this.arr[2]) {
							               heji1 += 0;
							           } else if (endHour <= this.arr[3]) {
							               heji1 = heji1 + endHour - this.arr[2];
							           } else {
							               heji1 = heji1 + endHour - this.arr[2];
							           }
							       } else if (startHour < this.arr[3]) {
							           if (endHour <= this.arr[3]) {
							               heji1 += endHour - startHour;
							           } else {
							               heji1 += this.arr[3] - startHour - -1;
							           }
							       } else {
							           heji1 += 1;
							       }
							console.log("合计"+heji1)
						}
						this.he.heji1=heji1;
						if (heji1 >= this.xian) {
							const newItem1 = {
								date: getDate(new Date(), +1).fullDate,
								info: '预约已满'
							}
							this.info.selected.push(newItem1);
						}
					});
				});
				getEquipment(this.shebeiid).then(res => {
					this.riqi.instrumentId = res.data.instrumentId;
					this.riqi.note2 = getDate(new Date(), +2).fullDate;
					// console.log("今日" + getDate(new Date(),+1).fullDate);
					this.riqi.note1 = 0;
					listAppointment(this.riqi).then(res => {
						this.tableriqi1 = res.rows;
						this.total = res.total;
						var heji2 = 0
						for (var i = 0; i < this.tableriqi1.length; i++) {
							let startHour = new Date(this.tableriqi1[i].appointmentStart).getHours();
							       let endHour = new Date(this.tableriqi1[i].appointmentEnd).getHours();
							       if (startHour < this.arr[0]) {
							           if (endHour <= this.arr[0]) {
							               heji2 += 0;
							           } else if (endHour <= this.arr[1]) {
							               heji2 += endHour - this.arr[0];
							           } else if (endHour <= this.arr[2]) {
							               heji2 += this.arr[1] - this.arr[0];
							           } else if (endHour <= this.arr[3]) {
							               heji2 += endHour - this.arr[0]- -this.arr[1]-this.arr[2];
										   console.log("heji0"+heji2);
							           } else {
							               heji2 += endHour - this.arr[0]- -this.arr[1]-this.arr[2];
							           }
							       } else if (startHour < this.arr[1]) {
							           if (endHour <= this.arr[1]) {
							               heji2 += endHour - startHour;
							           } else if (endHour <= this.arr[2]) {
							               heji2 += this.arr[1] - startHour;
							           } else if (endHour <= this.arr[3]) {
							               heji2 += endHour - startHour - 2;
							           } else {
							               heji2 += endHour - startHour - 2;
							           }
							       } else if (startHour < this.arr[2]) {
							           if (endHour <= this.arr[2]) {
							               heji2 += 0;
							           } else if (endHour <= this.arr[3]) {
							               heji2 = heji2 + endHour - this.arr[2];
							           } else {
							               heji2 = heji2 + endHour - this.arr[2];
							           }
							       } else if (startHour < this.arr[3]) {
							           if (endHour <= this.arr[3]) {
							               heji2 += endHour - startHour;
							           } else {
							               heji2 += this.arr[3] - startHour - -1;
							           }
							       } else {
							           heji2 += 1;
							       }
							console.log("heji2"+heji2);
						}
						this.he.heji2=heji2;
						if (heji2 >= this.xian) {
							const newItem2 = {
								date: getDate(new Date(), +2).fullDate,
								info: '预约已满'
							}
							this.info.selected.push(newItem2);
						}
					});
				});
				getEquipment(this.shebeiid).then(res => {
					this.riqi.instrumentId = res.data.instrumentId;
					this.riqi.note2 = getDate(new Date(), +3).fullDate;
					// console.log("今日" + getDate(new Date(),+1).fullDate);
					this.riqi.note1 = 0;
					listAppointment(this.riqi).then(res => {
						this.tableriqi1 = res.rows;
						this.total = res.total;
						var heji3 = 0
						for (var i = 0; i < this.tableriqi1.length; i++) {
							let startHour = new Date(this.tableriqi1[i].appointmentStart).getHours();
							       let endHour = new Date(this.tableriqi1[i].appointmentEnd).getHours();
							       if (startHour < this.arr[0]) {
							           if (endHour <= this.arr[0]) {
							               heji3 += 0;
							           } else if (endHour <= this.arr[1]) {
							               heji3 += endHour - this.arr[0];
							           } else if (endHour <= this.arr[2]) {
							               heji3 += this.arr[1] - this.arr[0];
							           } else if (endHour <= this.arr[3]) {
							               heji3 += endHour - this.arr[0]- -this.arr[1]-this.arr[2];
							           } else {
							               heji3 += endHour - this.arr[0]- -this.arr[1]-this.arr[2];
							           }
							       } else if (startHour < this.arr[1]) {
							           if (endHour <= this.arr[1]) {
							               heji3 += endHour - startHour;
							           } else if (endHour <= this.arr[2]) {
							               heji3 += this.arr[1] - startHour;
							           } else if (endHour <= this.arr[3]) {
							               heji3 += endHour - startHour - 2;
							           } else {
							               heji3 += endHour - startHour - 2;
							           }
							       } else if (startHour < this.arr[2]) {
							           if (endHour <= this.arr[2]) {
							               heji3 += 0;
							           } else if (endHour <= this.arr[3]) {
							               heji3 += endHour - this.arr[2];
							           } else {
							               heji3 += endHour - this.arr[2];
							           }
							       } else if (startHour < this.arr[3]) {
							           if (endHour <= this.arr[3]) {
							               heji3 += endHour - startHour;
							           } else {
							               heji3 += this.arr[3] - startHour - -1;
							           }
							       } else {
							           heji3 += 1;
							       }
							console.log(heji3);
						}
						this.he.heji3=heji3;
						if (heji3 >= this.xian) {
							const newItem3 = {
								date: getDate(new Date(), +3).fullDate,
								info: '预约已满'
							}
							this.info.selected.push(newItem3);
						}
					});
				});
				getEquipment(this.shebeiid).then(res => {
					this.riqi.instrumentId = res.data.instrumentId;
					this.riqi.note2 = getDate(new Date(), +4).fullDate;
					// console.log("今日" + getDate(new Date(),+1).fullDate);
					this.riqi.note1 = 0;
					listAppointment(this.riqi).then(res => {
						this.tableriqi1 = res.rows;
						this.total = res.total;
						var heji4 = 0
						for (var i = 0; i < this.tableriqi1.length; i++) {
							let startHour = new Date(this.tableriqi1[i].appointmentStart).getHours();
							       let endHour = new Date(this.tableriqi1[i].appointmentEnd).getHours();
							       if (startHour < this.arr[0]) {
							           if (endHour <= this.arr[0]) {
							               heji4 += 0;
							           } else if (endHour <= this.arr[1]) {
							               heji4 += endHour - this.arr[0];
							           } else if (endHour <= this.arr[2]) {
							               heji4 += this.arr[1] - this.arr[0];
							           } else if (endHour <= this.arr[3]) {
							               heji4 += endHour - this.arr[0]- -this.arr[1]-this.arr[2];
							           } else {
							               heji4 += endHour - this.arr[0]- -this.arr[1]-this.arr[2];
							           }
							       } else if (startHour < this.arr[1]) {
							           if (endHour <= this.arr[1]) {
							               heji4 += endHour - startHour;
							           } else if (endHour <= this.arr[2]) {
							               heji4 += this.arr[1] - startHour;
							           } else if (endHour <= this.arr[3]) {
							               heji4 += endHour - startHour - 2;
							           } else {
							               heji4 += endHour - startHour - 2;
							           }
							       } else if (startHour < this.arr[2]) {
							           if (endHour <= this.arr[2]) {
							               heji4 += 0;
							           } else if (endHour <= this.arr[3]) {
							               heji4 += endHour - this.arr[2];
							           } else {
							               heji4 += endHour - this.arr[2];
							           }
							       } else if (startHour < this.arr[3]) {
							           if (endHour <= this.arr[3]) {
							               heji4 += endHour - startHour;
							           } else {
							               heji4 += this.arr[3] - startHour - -1;
							           }
							       } else {
							           heji4 += 1;
							       }
							console.log(heji4);
						}
						this.he.heji4=heji4;
						if (heji4 >= this.xian) {
							const newItem4 = {
								date: getDate(new Date(), +4).fullDate,
								info: '预约已满'
							}
							this.info.selected.push(newItem4);
						}
					});
				});
				getEquipment(this.shebeiid).then(res => {
					this.riqi.instrumentId = res.data.instrumentId;
					this.riqi.note2 = getDate(new Date(), +5).fullDate;
					// console.log("今日" + getDate(new Date(),+1).fullDate);
					this.riqi.note1 = 0;
					listAppointment(this.riqi).then(res => {
						this.tableriqi1 = res.rows;
						this.total = res.total;
						var heji5 = 0
						for (var i = 0; i < this.tableriqi1.length; i++) {
							let startHour = new Date(this.tableriqi1[i].appointmentStart).getHours();
							       let endHour = new Date(this.tableriqi1[i].appointmentEnd).getHours();
							       if (startHour < this.arr[0]) {
							           if (endHour <= this.arr[0]) {
							               heji5 += 0;
							           } else if (endHour <= this.arr[1]) {
							               heji5 += endHour - this.arr[0];
							           } else if (endHour <= this.arr[2]) {
							               heji5 += this.arr[1] - this.arr[0];
							           } else if (endHour <= this.arr[3]) {
							               heji5 += endHour - this.arr[0]- -this.arr[1]-this.arr[2];
							           } else {
							               heji5 += endHour - this.arr[0]- -this.arr[1]-this.arr[2];
							           }
							       } else if (startHour < this.arr[1]) {
							           if (endHour <= this.arr[1]) {
							               heji5 += endHour - startHour;
							           } else if (endHour <= this.arr[2]) {
							               heji5 += this.arr[1] - startHour;
							           } else if (endHour <= this.arr[3]) {
							               heji5 += endHour - startHour - 2;
							           } else {
							               heji5 += endHour - startHour - 2;
							           }
							       } else if (startHour < this.arr[2]) {
							           if (endHour <= this.arr[2]) {
							               heji5 += 0;
							           } else if (endHour <= this.arr[3]) {
							               heji5 += endHour - this.arr[2];
							           } else {
							               heji5 += endHour - this.arr[2];
							           }
							       } else if (startHour < this.arr[3]) {
							           if (endHour <= this.arr[3]) {
							               heji5 += endHour - startHour;
							           } else {
							               heji5 += this.arr[3] - startHour - -1;
							           }
							       } else {
							           heji5 += 1;
							       }
							console.log(heji5);
						}
						this.he.heji5=heji5;
						if (heji5 >= this.xian) {
							const newItem5 = {
								date: getDate(new Date(), +5).fullDate,
								info: '预约已满'
							}
							this.info.selected.push(newItem5);
						}
					});
				});
				getEquipment(this.shebeiid).then(res => {
					this.riqi.instrumentId = res.data.instrumentId;
					this.riqi.note2 = getDate(new Date(), +6).fullDate;
					// console.log("今日" + getDate(new Date(),+1).fullDate);
					this.riqi.note1 = 0;
					listAppointment(this.riqi).then(res => {
						this.tableriqi1 = res.rows;
						this.total = res.total;
						var heji6 = 0
						for (var i = 0; i < this.tableriqi1.length; i++) {
							let startHour = new Date(this.tableriqi1[i].appointmentStart).getHours();
							       let endHour = new Date(this.tableriqi1[i].appointmentEnd).getHours();
							       if (startHour < this.arr[0]) {
							           if (endHour <= this.arr[0]) {
							               heji6 += 0;
							           } else if (endHour <= this.arr[1]) {
							               heji6 += endHour - this.arr[0];
							           } else if (endHour <= this.arr[2]) {
							               heji6 += this.arr[1] - this.arr[0];
							           } else if (endHour <= this.arr[3]) {
							               heji6 += endHour - this.arr[0]- -this.arr[1]-this.arr[2];
							           } else {
							               heji6 += endHour - this.arr[0]- -this.arr[1]-this.arr[2];
							           }
							       } else if (startHour < this.arr[1]) {
							           if (endHour <= this.arr[1]) {
							               heji6 += endHour - startHour;
							           } else if (endHour <= this.arr[2]) {
							               heji6 += this.arr[1] - startHour;
							           } else if (endHour <= this.arr[3]) {
							               heji6 += endHour - startHour - 2;
							           } else {
							               heji6 += endHour - startHour - 2;
							           }
							       } else if (startHour < this.arr[2]) {
							           if (endHour <= this.arr[2]) {
							               heji6 += 0;
							           } else if (endHour <= this.arr[3]) {
							               heji6 += endHour - this.arr[2];
							           } else {
							               heji6 += endHour - this.arr[2];
							           }
							       } else if (startHour < this.arr[3]) {
							           if (endHour <= this.arr[3]) {
							               heji6 += endHour - startHour;
							           } else {
							               heji6 += this.arr[3] - startHour - -1;
							           }
							       } else {
							           heji6 += 1;
							       }
							console.log(heji6);
						}
						this.he.heji6=heji6;
						if (heji6 >= this.xian) {
							const newItem6 = {
								date: getDate(new Date(), +6).fullDate,
								info: '预约已满'
							}
							this.info.selected.push(newItem6);
						}
					});
				});
				           



				// if(heji>=13)
				// {
				// 	this.info.selected = [
				// 						{
				// 							date: getDate(new Date()).fullDate,
				// 							info: '满'
				// 						}
				// 					]

				// }


			},

			submit() {

						if(this.riqi.note2==getDate(new Date()).fullDate&&this.he.heji>=this.xian)
						{this.$modal.msgError("当天时间段预约已满");}
						else if(this.riqi.note2==getDate(new Date(),+1).fullDate&&this.he.heji1>=this.xian)
						{this.$modal.msgError("当天时间段预约已满");}
						else if(this.riqi.note2==getDate(new Date(),+2).fullDate&&this.he.heji2>=this.xian)
						{this.$modal.msgError("当天时间段预约已满");}
						else if(this.riqi.note2==getDate(new Date(),+3).fullDate&&this.he.heji3>=this.xian)
						{this.$modal.msgError("当天时间段预约已满");}
						else if(this.riqi.note2==getDate(new Date(),+4).fullDate&&this.he.heji4>=this.xian)
						{this.$modal.msgError("当天时间段预约已满");}
						else if(this.riqi.note2==getDate(new Date(),+5).fullDate&&this.he.heji5>=this.xian)
						{this.$modal.msgError("当天时间段预约已满");}
						else if(this.riqi.note2==getDate(new Date(),+6).fullDate&&this.he.heji6>=this.xian)
						{this.$modal.msgError("当天时间段预约已满");}
						else{const id = this.$route.query.id;
				this.$tab.navigateTo('/pages/module/lyq/application?id=' + id + '&time=' + this.riqi.note2);}
				// const id = this.$route.query.id;
				// this.$tab.navigateTo('/pages/module/lyq/application?id=' + id + '&time=' + this.riqi.note2);

			},

			getListriqi() {
				// console.log("list1：" + this.riqi.instrumentId)
				// console.log("list2：" + this.riqi.note2)
				this.loading = true;
				listAppointment(this.riqi).then(res => {
					this.tableriqi = res.rows;
					this.total = res.total;
					this.loading = false;
				});
			},


			getNowTime() {
				var now = new Date();
				var year = now.getFullYear(); //得到年份
				var month = now.getMonth(); //得到月份
				var date = now.getDate(); //得到日期
				month = month + 1;
				month = month.toString().padStart(2, "0");
				date = date.toString().padStart(2, "0");
				var defaultDate = `${year}-${month}-${date}`;
				return defaultDate;
			},
			getBeforeDate(num, time) {
				let n = num;
				let d = '';
				if (time) {
					d = new Date(time);
				} else {
					d = new Date();
				}
				let year = d.getFullYear();
				let mon = d.getMonth() + 1;
				let day = d.getDate();
				if (day <= n) {
					if (mon > 1) {
						mon = mon - 1;
					} else {
						year = year - 1;
						mon = 12;
					}
				}
				d.setDate(d.getDate() - n);
				year = d.getFullYear();
				mon = d.getMonth() + 1;
				day = d.getDate();
				let s = year + "-" + (mon < 10 ? ('0' + mon) : mon) + "-" + (day < 10 ? ('0' + day) : day);
				return s;
			},


			// 打开窗口
			showDrawer(e) {
				this.$refs[e].open()
			},
			// 关闭窗口
			closeDrawer(e) {
				this.$refs[e].close()
			},
			// 抽屉状态发生变化触发
			// change(e, type) {
			// 	console.log(e)
			// 	console.log((type === 'showLeft' ? '左窗口' : '右窗口') + (e ? '打开' : '关闭'));
			// 	this[type] = e
			// },
			getList() {
				this.loading = true;
				listAppointment(this.queryParams).then(res => {
					this.table = res.rows;
					this.total = res.total;
					this.loading = false;
				});
			},

			monthSwitch(e) {
				console.log('monthSwitchs 返回:', e)
			}
		}
	}
</script>
<style lang="scss">
	.example-body {
		/* #ifndef APP-NVUE */
		display: flex;
		/* #endif */
		flex-direction: row;
	}

	.aaa {
		width: 100%;
	}

	.close {
		padding: 10px;
	}

	page {
		background-color: #ffffff;
	}

	.title {
		margin-top: 3%;
		margin-left: 4%;
		color: #000000;
	}

	.content {
		margin-top: 3%;
		color: #000000;
	}

	.title1 {
		margin-top: 3%;
		margin-left: 4%;
		color: #000000;
	}

	.content1 {
		margin-top: 3%;
		color: #000000;
	}

	.scroll-view {
		/* #ifndef APP-NVUE */
		width: 100%;
		height: 100%;
		/* #endif */
		flex: 1
	}

	// 处理抽屉内容滚动
	.scroll-view-box {
		flex: 1;
		position: absolute;
		top: 0;
		right: 0;
		bottom: 0;
		left: 0;
	}

	.card-text {
		text-align: center;
	}

	.calendar-button {
		flex: 1;
		font-weight: bold;
		font-size: 32rpx;
	}

	.example-info {
		margin-top: 20px;
		margin-left: 20px;
		font-weight: bold;
		color: #000;
	}

	.mini {
		background-color: #1E90FF;
		color: #ffffff;

		justify-content: space-around;
	}

	.title-split {
		margin-top: 10px;
		text-align: center;
		font-size: 16px;
		font-weight: bold;
	}

	.divider {
		margin-top: 3%;
		margin-bottom: 3%;
		margin-right: 2%;
		margin-left: 2%;
		background: #E0E3DA;
		width: 100%;
		height: 1rpx;
	}

	.el-calendar .disabled-cell {
		cursor: not-allowed;
		color: #ccc;
	}
</style>
